#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int maxn = 1e5+5;

struct book{
	int id;
	int wet;
}arr[maxn];
void solve(){
	int n;
	cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> arr[i].id >> arr[i].wet;
	}
	int stp = n/2;
	while(stp >= 1){
		for (int i=stp+1;i<=n;i++) {
			book b = arr[i];
			int j=i-stp;
			while(j>=1 && (arr[j].wet > b.wet || (arr[j].wet == b.wet && arr[j].id > b.id))){
				arr[j+stp] = arr[j]; // 往后挪
				j -= stp;
			}
			arr[j+stp] = b;
		}		
		stp /= 2;
	}
	
	for (int i=1;i<=n;i++) {
		cout << arr[i].id << ' ';
	}
}


signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	while(t--){
		solve();
	}
	return 0;
}
